const fs = require('fs');
const path = require('path');

const targetDir = '../../assets/LevelAb'; // ← 这里修改为你的目标路径

function processMetaFiles(dir) {
  const files = fs.readdirSync(dir);

  for (const file of files) {
    const fullPath = path.join(dir, file);
    const stat = fs.statSync(fullPath);

    if (stat.isDirectory()) {
      processMetaFiles(fullPath); // 递归子文件夹
    } else if (file.endsWith('_b.png.meta')) {
      try {
        const content = fs.readFileSync(fullPath, 'utf-8');
        const json = JSON.parse(content);

        // 检查是否已有正确值
        if (json.premultiplyAlpha !== true) {
          json.premultiplyAlpha = true;
          fs.writeFileSync(fullPath, JSON.stringify(json, null, 2));
          console.log(`✅ 已修改: ${fullPath}`);
        } else {
          console.log(`⏩ 已是 true: ${fullPath}`);
        }
      } catch (err) {
        console.error(`❌ 处理失败: ${fullPath}`, err.message);
      }
    }
  }
}

processMetaFiles(targetDir);
